<template>
    <div class="searchPage">
        <div class="searchTop">
            <van-search
                v-model="value"
                show-action
                placeholder="请输入搜索关键词"
                :value="$route.query.content"
                @search="onSearch"
                @cancel="onCancel"
            />
        </div> 
        <router-view></router-view>
    </div>
</template>

<script>
import { Toast } from 'vant';
import { Icon } from 'vant';
export default {
    name:'SearchPage',
    data() {
        return {
            value: '',
            isSearch:false
        }
    },
    // beforeRouteUpdate(to,from,next){
    //     console.log(to)
    // },
    methods: {
        onSearch(val) {
            //点击回车进行搜索之后
            this.isSearch = true
            let pathLength = this.$route.path.split('/').length
            //如果当前不是在用户界面，就搜出来帖子
            if(this.$route.path.split('/')[pathLength-1] !== 'user'){
                this.$router.replace({
                    path:'/search-page/search-more/post',
                    query: {
                        content: this.value
                    }
                })
            }else{
                this.$router.replace({
                    path:'/search-page/search-more/user',
                    query: {
                        content: this.value
                    }
                })
            }
            
        },
        onCancel() {
            history.go(-1)
        },
    },
}
</script>

<style lang="less" scoped>
    .searchPage{
        background-color: #fafafa; 
        height: 100vh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
</style>